package com.heima.controller.v1;

import com.heima.article.dto.ArticleDto;
import com.heima.article.dto.ArticleHomeDto;
import com.heima.common.constant.ArticleConstants;
import com.heima.common.dtos.ResponseResult;
import com.heima.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/article")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @PostMapping("/load")
    public ResponseResult mainArticle(@RequestBody ArticleHomeDto articleHomeDto) {
        return articleService.load(ArticleConstants.LOADTYPE_LOAD_MORE, articleHomeDto);
    }

    @PostMapping("/loadmore")
    public ResponseResult loadMore(@RequestBody ArticleHomeDto articleHomeDto) {
        return articleService.load(ArticleConstants.LOADTYPE_LOAD_MORE, articleHomeDto);
    }

    @PostMapping("/loadnew")
    public ResponseResult loadNew(@RequestBody ArticleHomeDto articleHomeDto) {
        return articleService.load(ArticleConstants.LOADTYPE_LOAD_NEW, articleHomeDto);
    }


    /**
     * 当自媒体文章审核通过时，通过Feign调用当前方法将文章存进数据库
     *
     * @param dto
     * @return
     */
    @PostMapping("/save")
    public Long saveNews(@RequestBody ArticleDto dto) {
        return articleService.saveNews(dto);
    }
}
